#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=300;
typedef int LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[maxn],b[maxn];
LL dp[maxn][40100];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n;cin>>n;
  for(LL i=1;i<=n;i++){
    cin>>a[i];cin>>b[i];
  }
  memset(dp,0x3f,sizeof(dp));
  for(LL j=0;j<=40000;j++){
     dp[0][j]=0;
  }
  for(LL i=1;i<=n;i++){
    for(LL j=0;j<=40000;j++){
        if(j>=a[i]){
            dp[i][j]=min(dp[i-1][j-a[i]],dp[i-1][j]+b[i]);
        }
        else dp[i][j]=min(dp[i-1][j]+b[i],dp[i][j]);
    }
  }
  LL ans=0x3f3f3f3f;
  for(LL j=0;j<=40000;j++){
    ans=min(ans,max(j,dp[n][j]));
  }
  cout<<ans<<"\n";
return 0;
}
